const app = getApp()
import {
    util,
    Toast,
    Dialog,
    commonMixin
} from "../../utils/util.js";
Page({
    behaviors: [commonMixin],
    /**
     * 页面的初始数据
     */
    data: {
        sampleList1:[],
        sampleList2:[],
        active:0,
        statusOptions:[],
        page:1,
    },
    //复制订单号
    copy(e){
        let copytxt = e.currentTarget.dataset.order;
        wx.setClipboardData({
            data: copytxt,
            success (res) {

            }
        })
    },
  
    onLoad(options) {
    },
    onTabItemTap(item) {
      console.log('点击了tab项', item);
      let userInfo = util.getUserInfo()
      if (!userInfo.status) {
        app.globalData.loginFlag = true;
        this.navToUrl('/pages/my/index');
      }
    },
    onShow() {
      this.setData({
        page:1,
        sampleList1:[],
        sampleList2:[],
      })
      this.getDataList();
    },
    // onReachBottom() {
    //     this.getDataList();
    // },
    onShareAppMessage() {

    },

    handleCodeCopy(e) {
      let copytxt = e.currentTarget.dataset.code;
      wx.setClipboardData({
        data: copytxt,
        success(res) {
          Toast("检测码拷贝成功！");
        }
      })
    },

    handleJumpCheck(e) {
      let sample_sn = e.currentTarget.dataset.sample_sn;
      wx.navigateTo({
          url: '/pages/check/index?sampleSn='+sample_sn,
      })
    },

    handlePreviewQrcode(event) {
      console.log('handlePreviewQrcode', event);
      wx.previewImage({
          urls: [event.currentTarget.dataset.url]
      })
    },

    //获取订单列表
    getDataList(isReset) {
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        if (isReset) {
            this.setData({
                page:1,
                sampleList1:[],
                sampleList2:[]
            })
        }
        util.http.post("v1/mini/appointment-get-list",{
            page:this.data.page
        }).then((res)=>{
            let list1 = res.data.data.list1;
            let list2 = res.data.data.list2;
            this.setData({
              statusOptions:res.data.data.status_options
            })
            if(list1.length>0){
              this.setData({
                sampleList1:list1
              })
            }
            if(list2.length>0){
              this.setData({
                sampleList2:list2
              })
            }
            // if(list.data && list.data.length>0){
            //     //合并数据
            //     let sampleList = [...this.data.sampleList,...list.data];
            //     this.setData({
            //       sampleList:sampleList
            //     })
            //     //上拉刷新
            //     if(list.data && list.data.length>0){
            //         let page = this.data.page;
            //         this.setData({
            //             page:page+1
            //         })
            //     }
            // }
            wx.hideLoading();
        }).catch((err)=>{
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
            console.log(err)
        })
    }
})